package com.xyyl.patient.core.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

/**
 * 
 * @filename PropertiesUtil.java
 * @author zhucx
 * @date 2017-04-17 09:34:02
 */
public class PropertiesUtil {

	private static Logger logger = Logger.getLogger(PropertiesUtil.class);

	public static Properties getProperties(String path) {

		logger.info("load properties file [" + path + "]...");

		Properties props = new Properties();

		InputStream inStream = null;
		try {
			inStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);

			if (null == inStream){
				logger.info("not exists properties file [" + path + "]");
				return props;
			}
			
			props.load(inStream);

			logger.info("load properties file successfully.");
		} catch (IOException e) {
			logger.error("load path[" + path + "] error: ", e);
		} finally {
			if (null != inStream) {
				try {
					inStream.close();
				} catch (IOException e) {
					logger.error("close input stream error: ", e);
				}
			}
		}

		return props;
	}
	
}
